var helpJsonData;
var helpType;
var help_scrollPosition;
var settings = {
	autoReinitialise : true
};

jQuery(function() {
	console.log("------>", helpJsonData);

	jQuery("#help-content-data").empty();
	if (helpJsonData) {
		console.log("-----> data available");
		for (var i = 0; i < helpJsonData.help.length; i++) {
			console.log(helpJsonData.help[0].type);
			if (helpJsonData.help[i].type == helpType) {
				console.log("helpJsonData.help[i].title:", helpJsonData.help[i].title);
				jQuery("#help_data_title").text("Help: " + helpJsonData.help[i].title);
				jQuery("#help-content-data").append(helpJsonData.help[i].instruction);
				scrollTo(help_scrollPosition);
			}
		}
	
		var pane = jQuery('.scroll-pane')
		pane.jScrollPane(settings);

	} else {

		jQuery.ajax({
			url : "/ce-static-testedge/common/data/help.json",
			type : "get",
			success : function(result) {
				console.log("result:", result);
				helpJsonData = result;
				for (var i = 0; i < result.help.length; i++) {
					console.log(result.help[0].type);
					if (result.help[i].type == helpType) {
						jQuery("#help_data_title").text("Help: " + result.help[i].title);
						jQuery("#help-content-data").append(result.help[i].instruction);
						console.log("helpJsonData.help[i].title:", helpJsonData.help[i].title);
						scrollTo(help_scrollPosition);
					}
				}

				var pane = jQuery('.scroll-pane')
				pane.jScrollPane(settings);
			},
			error : function(jqXHR, textStatus, errorThrown) {
				console.log("error", jqXHR);
				console.log("error", textStatus);
			}
		});
	}

	//var helpJsonData =  jQuery.parseJSON(helpJson);

});

function scrollTo(hash) {
	console.log("------> scroll to", document.body.scrollTop);
	var yScroll = document.body.scrollTop;
	//	window.location.hash = id;
	window.location.hash = "#" + hash;
	//document.body.scrollTop=yScroll;
	document.body.scrollTop = yScroll;
	console.log("------> scroll to", document.body.scrollTop);
}
